import 'package:dio/dio.dart';
import 'package:dio/adapter.dart';

BaseOptions options = BaseOptions(
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
  },
);

class HttpUtil {
  late Dio _dio;

  static final HttpUtil _instance = HttpUtil._internal();

  factory HttpUtil() {
    return _instance;
  }

  HttpUtil._internal() {
    _dio = Dio(options);
    (_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
        (client) {
      // client.findProxy = (uri) {
      //   return "PROXY 192.168.253.1:8888";
      // };

      client.badCertificateCallback = (cert, host, port) {
        return true;
      };
    };

    print("options.connectTimeout ${_dio.options.connectTimeout}");
    print("options.receiveTimeout ${_dio.options.receiveTimeout}");
  }

  Future get(String url, Map<String, dynamic> queryParameters) async {
    Response response = await _dio.get(url, queryParameters: queryParameters);
    return response;
  }

  Future post(String url, Map<String, dynamic> queryParameters) async {
    Response response = await _dio.post(url, queryParameters: queryParameters);
    return response;
  }
}
